package main

import (
	//"fmt"
	"math/rand"
	"time"
)

//作业8 对数组进行排序
/*
func main() {

	arr := getArr()
	fmt.Println("排序之前", arr)
	fmt.Println("排序之后", Sort(arr, false))

}
*/
//获取数组
func getArr() []int {
	var arr []int
	for i := 0; i < 10; i++ {
		time.Sleep(time.Duration(10) * time.Millisecond)
		rand.Seed(time.Now().UnixNano())
		arr = append(arr, rand.Intn(100))
	}
	return arr
}

//排序
func Sort(arr []int, re bool) []int {
	for i := 0; i < len(arr)-1; i++ {
		for j := 0; j < len(arr)-i-1; j++ {
			if GetRe(arr[j], arr[j+1], re) {
				temp := arr[j]
				arr[j] = arr[j+1]
				arr[j+1] = temp
			}
		}
	}

	return arr
}

//选择顺序还是倒序
func GetRe(a int, b int, re bool) bool {

	if re {
		re = (a > b)
	} else {
		re = (b > a)
	}
	return re
}
